package com.taxi.driver.module.main.mine.wallet.rules;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.taxi.driver.R;
import com.taxi.driver.api.ApiConfig;
import com.taxi.driver.common.AppConfig;
import com.taxi.driver.common.Application;
import com.taxi.driver.common.BaseActivity;
import com.taxi.driver.module.main.mine.wallet.rules.dagger.DaggerRulesActivityComponent;
import com.taxi.driver.module.main.mine.wallet.rules.dagger.RulesActivityModule;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 规则说明
 */
public class RulesActivity extends BaseActivity implements RulesContract.View {
    @BindView(R.id.web_view)
    WebView web_view;

    @Inject
    RulesPresenter mPresenter;

    String url;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rules);
        ButterKnife.bind(this);

        DaggerRulesActivityComponent.builder()
                .appComponent(Application.getAppComponent())
                .rulesActivityModule(new RulesActivityModule(this))
                .build().inject(this);

        url = AppConfig.HOST + mPresenter.getRuleExplain();
        web_view.getSettings().setJavaScriptEnabled(true);
        web_view.setWebViewClient(new ReWebViewClient());
        web_view.loadUrl(url);

    }

    public class ReWebViewClient extends WebViewClient {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            showLoadingView(true);
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            hideLoadingView();
            super.onPageFinished(view, url);
        }
    }

    @Override
    public boolean isActive() {
        return false;
    }

}
